package puzzle.common.point;

public class Pnt implements Comparable<Pnt> {
	public static final Pnt[] EMPTY_ARRAY = new Pnt[0];
	
	public final int x;
	public final int y;

	public Pnt(int x, int y) {
		this.x = x;
		this.y = y;
	}

	public Pnt add(Vct v) {
		return new Pnt(this.x + v.dx, this.y + v.dy);
	}

	public Pnt add(Vct v, int scale) {
		return new Pnt(this.x + v.dx * scale, this.y + v.dy * scale);
	}

	public Vct vctTo(Pnt p) {
		return new Vct(p.x - x, p.y - y);
	}
	
	public int getManhattanDistanceTo(Pnt p) {
		return Math.abs(p.x - x) + Math.abs(p.y - y);
	}

	@Override
	public boolean equals(Object o0) {
		if (o0 instanceof Pnt) {
			Pnt o = (Pnt) o0;
			return o.x == x && o.y == y;
		} else {
			return false;
		}
	}
	
	@Override
	public int hashCode() {
		return x * 13 + y;
	}
	
	@Override
	public String toString() {
		return "[" + x + "," + y + "]";
	}

	public int compareTo(Pnt other) {
		if (y < other.y) {
			return -1;
		} else if (y > other.y) {
			return 1;
		} else {
			if (x < other.x) {
				return -1;
			} else if (x > other.x ){
				return 1;
			} else {
				return 0;
			}
		}
	}
}
